package cn.iocoder.yudao.module.bpm.service.oa.listener;

import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceStatusEvent;
import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceStatusEventListener;
import cn.iocoder.yudao.module.bpm.service.journalapply.JournalApplyService;
import cn.iocoder.yudao.module.bpm.service.journalapply.JournalApplyServiceImpl;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOALeaveService;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOALeaveServiceImpl;
import cn.iocoder.yudao.module.bpm.service.sourceapply.SourceApplyService;
import cn.iocoder.yudao.module.bpm.service.sourceapply.SourceApplyServiceImpl;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * OA 请假单的结果的监听器实现类
 *
 * @author 源码
 */
@Component
public class BpmOALeaveStatusListener extends BpmProcessInstanceStatusEventListener {

    @Resource
    private BpmOALeaveService leaveService;
    @Resource
    private JournalApplyService journalApplyService;
    @Resource
    private SourceApplyService sourceApplyService;


    @Override
    protected String getProcessDefinitionKey() {
        return BpmOALeaveServiceImpl.PROCESS_KEY;
    }

    @Override
    protected void onEvent(BpmProcessInstanceStatusEvent event) {
        if(event.getProcessDefinitionKey().equals(BpmOALeaveServiceImpl.PROCESS_KEY)) {
            leaveService.updateLeaveStatus(Long.parseLong(event.getBusinessKey()), event.getStatus());
        } else if (event.getProcessDefinitionKey().equals(JournalApplyServiceImpl.PROCESS_KEY)) {
            journalApplyService.updateLeaveStatus(Long.parseLong(event.getBusinessKey()), event.getStatus());
        } else if (event.getProcessDefinitionKey().equals(SourceApplyServiceImpl.PROCESS_KEY)) {
            sourceApplyService.updateLeaveStatus(Long.parseLong(event.getBusinessKey()), event.getStatus());
        }

    }

}
